//
//  ShareBtn.m
//  Share'
//
//  Created by jarze on 15/7/18.
//  Copyright (c) 2015年 jarze. All rights reserved.
//

#import "ShareBtn.h"
#import <ShareSDK/ShareSDK.h>

@implementation ShareBtn

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
    
        [self addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
       
    }

    return self;

}

- (void)share:(UIButton *)sender
{
    
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ShareSDK" ofType:@"png"];
    NSString *imagePath2 = [[NSBundle mainBundle] pathForResource:@"001" ofType:@"jpg"];
    
    //构造分享内容
    id<ISSContent> publishContent = [ShareSDK content:@"http://www.mob.com"
                                       defaultContent:@"测试一下"
                                                image:[ShareSDK imageWithPath:imagePath]
                                                title:@"ShareSDK"
                                                  url:nil //@"http://www.mob.com"
                                          description:@"这是一条测试信息"
                                            mediaType:SSPublishContentMediaTypeNews];
    //创建弹出菜单容器
    id<ISSContainer> container = [ShareSDK container];
    
 //   [container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
    
    
    //自定义新浪微博发送内容
    [publishContent addSinaWeiboUnitWithContent:@"3:12" image:[ShareSDK imageWithPath:imagePath2]
                             locationCoordinate:nil];
    
    //指定菜单弹出的分享平台列表
//    NSArray *shareList = [ShareSDK customShareListWithType:
//                          SHARE_TYPE_NUMBER(ShareTypeSinaWeibo),
//                          SHARE_TYPE_NUMBER(ShareTypeQQSpace),
//                          SHARE_TYPE_NUMBER(ShareTypeQQ),
//                          //                          SHARE_TYPE_NUMBER(ShareTypeTwitter),
//                          //                          SHARE_TYPE_NUMBER(ShareTypeRenren),
//                          //                          SHARE_TYPE_NUMBER(ShareTypeMail),
//                          SHARE_TYPE_NUMBER(ShareTypeWeixiTimeline),
//                          //                          SHARE_TYPE_NUMBER(ShareTypeYouDaoNote),
//                          //                          SHARE_TYPE_NUMBER(ShareTypeTencentWeibo),
//                          nil];
    
    
    NSArray *shareList = [ShareSDK getShareListWithType:
                          ShareTypeSinaWeibo,        /**< 新浪微博 */
                          ShareTypeTencentWeibo,      /**< 腾讯微博 */
                          ShareTypeDouBan ,            /**< 豆瓣社区 */
                          ShareTypeQQSpace,           /**< QQ空间 */
                          ShareTypeFacebook,         /**< Facebook */
                          ShareTypeTwitter ,          /**< Twitter */
                          ShareTypeWeixiSession ,     /**< 微信好友 */
                          ShareTypeWeixiTimeline,    /**< 微信朋友圈 */
                          ShareTypeQQ ,               /**< QQ */
                          nil];
    
    
    
    
    
    //弹出分享菜单
    [ShareSDK showShareActionSheet:container
                         shareList:shareList
                           content:publishContent
                     statusBarTips:YES
                       authOptions:nil
                      shareOptions:nil
                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                
                                if (state == SSResponseStateSuccess)
                                {
                                    
                                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"分享成功" message:nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
                                    alert.alertViewStyle = UIAlertViewStyleDefault;
                                    [alert show];
                                    
                                    // NSLog(NSLocalizedString(@"TEXT_ShARE_SUC", @"分享成功"));
                                }
                                else if (state == SSResponseStateFail)
                                {
                                    
                                    
                                    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"分享失败" message: [error errorDescription] delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:nil, nil];
                                    [alert show];
                                    
                                    //NSLog(NSLocalizedString(@"TEXT_ShARE_FAI", @"分享失败,错误码:%d,错误描述:%@"), [error errorCode], [error errorDescription]);
                                }
                            }];
    

}



@end
